package cn.dceast.common.utils;

import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class FrameUtil {
	public static Logger logger = Logger.getLogger(FrameUtil.class);
	/**
	 * 将字符串写成json格式返回响应
	 * @param json
	 * @param response
	 */
	public static void responseJson(String json, HttpServletResponse response) {
		 response.setCharacterEncoding("UTF-8");  
		    response.setContentType("text/plain; charset=utf-8");
		    PrintWriter out = null;
		    try {  
		        out = response.getWriter();  
		        out.append(json);  
		    } catch (IOException e) {
		        e.printStackTrace();
		        logger.error("====响应客户端写入数据时发生错误=======", e);
		    } finally {  
		        if (out != null) {  
		            out.close();  
		        }  
		    }  
	}
}
